<template>
  <!-- 回退客户组件 -->
  <div>
    <el-button type="primary" size="mini" @click="returnBtn()">批量回退</el-button>
    <el-dialog title="请填写回退信息" :visible.sync="dialogFormVisible">
      <el-form>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="回退理由" :label-width="formLabelWidth">
              <el-input size="mini" v-model="reasonReturn" autocomplete="off"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="回退类型" :label-width="formLabelWidth">
              <el-select size="mini" v-model="returnType" placeholder="请选择回退类型">
                <el-option label="空号" value="A"></el-option>
                <el-option label="三无" value="B"></el-option>
                <el-option label="停机" value="C"></el-option>
                <el-option label="无意向" value="D"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" @click="dialogFormVisible = false">取 消</el-button>
        <el-button
        size="mini"
          type="primary"
          @click="
            dialogFormVisible = false;
            back_sure();
          "
          >确认回退</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>

<script>
import Api from "@/http/apis/modules/custManagement.js";
import { Message } from "element-ui";
export default {
  props: {
    returnArr: {
      type: Array,
      default: [],
    },
  },
  data() {
    return {
      // 回退功能
      dialogFormVisible: false,
      formLabelWidth: "100px",
      returnType: "B", //回退类型
      reasonReturn: "", //回退理由
      returnSel: {},
    };
  },
  methods: {
    // 点击回退
    returnBtn() {
      if (this.returnArr.length == 0) {
        this.$message({
          type: "error",
          message: "请选择数据！",
        });
      } else {
        this.dialogFormVisible = true;
      }
    },
    // 确认回退
    async back_sure() {
      this.returnArr.forEach((item) => {
        for (let key in item) {
          item["reasonReturn"] = this.reasonReturn;
          item["returnType"] = this.returnType;
        }
      });
      let re = await Api.returnCustApi(this.returnArr);
      console.log(re);
      if (
        re.data.result.result != undefined &&
        re.data.result.returnInfo != undefined
      ) {
        let { result } = re.data.result;
        if (result === true) {
          Message({
            type: "success",
            message: "回退成功",
          });
          
          this.$emit("upDateList");
        } else {
          Message.error("回退失败");
        }
      }
      console.log("回退数据", this.returnArr);
      this.reasonReturn = "";
    },
  },
  created() {},
};
</script>

<style lang="less" scoped>
/* 遮罩 */
#mask {
  width: 100%;
  height: 100%;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 10000;
};
</style>